{extend name='public/base' /}
{block name='content'}
{include file='public/content_header' /}
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <!-- 表单头部 -->
                <div class="box-header with-border">
                    <div class="btn-group">
                        <a class="btn flat btn-sm btn-default BackButton">
                            <i class="fa fa-arrow-left"></i>
                            返回
                        </a>
                    </div>
                </div>
                <!-- 表单 -->
                <form id="dataForm" class="form-horizontal dataForm" action="" method="post"
                      enctype="multipart/form-data">
                    <!-- 表单字段区域 -->
                    <div class="box-body">
                        <div class="form-group">
                            <label for="department_id" class="col-sm-2 control-label">部门</label>
                            <div class="col-sm-10 col-md-4">
                                <select name="department_id" id="department_id" {if isset($data) &&
                                        isset($data.staff_id)} disabled=true{/if} class="form-control field-select"
                                        data-placeholder="请选择部门">
                                    <option value=""></option>
                                    {$department_list|raw}
                                </select>
                            </div>
                        </div>
                        <script>
                            $('#department_id').select2();
                            $('#department_id').change(function () {
                                let departmentId = $(this).val();
                                let option = "BasicSalary";
                                $.ajax({
                                    url: "{:url('attendance/getStaffByDepartmentId')}",
                                    type: "post",
                                    data: {"departmentId": departmentId,'option':option},
                                    dataType: "json",
                                    sync: false,
                                    success: function (res) {
                                        if (res.code===0){
                                            layer.alert(res.msg, {
                                                icon: 0,
                                                skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                                            })
                                            $('#staff_id').empty();
                                        } else {

                                            $('#staff_id').empty();
                                            $('#staff_id').append(`<option value=""></option>`);
                                            var _html = '';
                                            $.each(res.data,function (e,v) {

                                                _html  +=
                                                    `<option value="${v.id}">${v.name}</option>`
                                                ;
                                            })
                                            $('#staff_id').append(_html).trigger('change.select2');
                                            $('#staff_id').select2();
                                            $('#department_id-error').empty();
                                            $('#staff_id-error').empty();
                                        }
                                    }
                                })
                            });

                        </script>
                        <div class="form-group">
                            <label for="staff_id" class="col-sm-2 control-label">员工</label>
                            <div class="col-sm-10 col-md-4">
                                <select name="staff_id" id="staff_id" {if isset($data) &&
                                        isset($data.staff_id)} disabled=true{/if} class="form-control field-select"
                                        data-placeholder="请选择员工">
                                    {if isset($data)}
                                    <option value=""></option>
                                    {foreach name='staff_list' id='item'}
                                    <option value="{$item.id}" {if isset($data) &&
                                            $data.staff_id==$item.id}selected{/if}>
                                        {$item.name}
                                    </option>
                                    {/foreach}
                                    {/if}
                                </select>
                            </div>
                        </div>
                        <script>
                            $('#staff_id').select2();
                            $('#staff_id').on("select2:open",function (e) {
                                if ($("#department_id").val() === ''){
                                    layer.alert('请先选择部门', {
                                        icon: 0,
                                    })
                                }
                            });
                            $('#staff_id').on("change",function (e) {
                                jQuery.ajax({
                                    type: 'post',
                                    async:false,
                                    data:{'staff_id':$('#staff_id').val()},
                                    url: "{:url('basic_salary/nameUnique')}",
                                    dataType: 'json',
                                    success: function (result) {
                                        if (result.code == 0) {
                                            layer.alert('已存在此员工信息', {
                                                icon: 0,
                                            })
                                        }
                                        else {
                                        }
                                    },
                                    error: function () {
                                    }
                                });
                            })
                        </script>
                        <div class="form-group">
                            <div class="col-sm-10 col-md-4">
                                <div class="input-group">
                                    <input id="insure_id" type="hidden" name="insure_id" value="{$data.insure_id|default=''}"
                                           placeholder="社保关系" type="number" class="form-control field-number">
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="basic_salary" class="col-sm-2 control-label">基本工资</label>
                            <div class="col-sm-10 col-md-4">
                                <div class="input-group">
                                    <input id="basic_salary" name="basic_salary" value="{$data.basic_salary|default=''}"
                                           placeholder="请输入基本工资" type="number" class="form-control field-number">
                                </div>
                            </div>
                        </div>
<!--                        <script>-->
<!--                            $('#basic_salary')-->
<!--                                .bootstrapNumber({-->
<!--                                    upClass: 'success',-->
<!--                                    downClass: 'primary',-->
<!--                                    center: true-->
<!--                                });-->
<!--                        </script>-->
                        <div class="form-group">
                            <label for="manage_salary" class="col-sm-2 control-label">管理工资</label>
                            <div class="col-sm-10 col-md-4">
                                <div class="input-group">
                                    <input id="manage_salary" name="manage_salary"
                                           value="{$data.manage_salary|default=''}" placeholder="请输入管理工资" type="number"
                                           class="form-control field-number">
                                </div>
                            </div>
                        </div>
<!--                        <script>-->
<!--                            $('#manage_salary')-->
<!--                                .bootstrapNumber({-->
<!--                                    upClass: 'success',-->
<!--                                    downClass: 'primary',-->
<!--                                    center: true-->
<!--                                });-->
<!--                        </script>-->
                        <div class="form-group">
                            <label for="title_salary" class="col-sm-2 control-label">职称津贴</label>
                            <div class="col-sm-10 col-md-4">
                                <div class="input-group">
                                    <input id="title_salary" name="title_salary" value="{$data.title_salary|default=''}"
                                           placeholder="请输入职称津贴" type="number" class="form-control field-number">
                                </div>
                            </div>
                        </div>
<!--                        <script>-->
<!--                            $('#title_salary')-->
<!--                                .bootstrapNumber({-->
<!--                                    upClass: 'success',-->
<!--                                    downClass: 'primary',-->
<!--                                    center: true-->
<!--                                });-->
<!--                        </script>-->
                        <div class="form-group">
                            <label for="education_salary" class="col-sm-2 control-label">学历津贴</label>
                            <div class="col-sm-10 col-md-4">
                                <div class="input-group">
                                    <input id="education_salary" name="education_salary"
                                           value="{$data.education_salary|default=''}" placeholder="请输入学历津贴"
                                           type="number" class="form-control field-number">
                                </div>
                            </div>
                        </div>
<!--                        <script>-->
<!--                            $('#education_salary')-->
<!--                                .bootstrapNumber({-->
<!--                                    upClass: 'success',-->
<!--                                    downClass: 'primary',-->
<!--                                    center: true-->
<!--                                });-->
<!--                        </script>-->
                        <div class="form-group">
                            <label for="nightwork_salary" class="col-sm-2 control-label">夜班津贴</label>
                            <div class="col-sm-10 col-md-4">
                                <div class="input-group">
                                    <input id="nightwork_salary" name="nightwork_salary"
                                           value="{$data.nightwork_salary|default=''}" placeholder="请输入夜班津贴"
                                           type="number" class="form-control field-number">
                                </div>
                            </div>
                        </div>
<!--                        <script>-->
<!--                            $('#nightwork_salary')-->
<!--                                .bootstrapNumber({-->
<!--                                    upClass: 'success',-->
<!--                                    downClass: 'primary',-->
<!--                                    center: true-->
<!--                                });-->
<!--                        </script>-->
                        <div class="form-group">
                            <label for="payscale_salary" class="col-sm-2 control-label">薪级工资</label>
                            <div class="col-sm-10 col-md-4">
                                <div class="input-group">
                                    <input id="payscale_salary" name="payscale_salary"
                                           value="{$data.payscale_salary|default=''}" placeholder="请输入薪级工资"
                                           type="number" class="form-control field-number">
                                </div>
                            </div>
                        </div>
<!--                        <script>-->
<!--                            $('#payscale_salary')-->
<!--                                .bootstrapNumber({-->
<!--                                    upClass: 'success',-->
<!--                                    downClass: 'primary',-->
<!--                                    center: true-->
<!--                                });-->
<!--                        </script>-->
                        <div class="form-group">
                            <label for="secret_salary" class="col-sm-2 control-label">保密工资</label>
                            <div class="col-sm-10 col-md-4">
                                <div class="input-group">
                                    <input id="secret_salary" name="secret_salary"
                                           value="{$data.secret_salary|default=''}" placeholder="请输入保密工资" type="number"
                                           class="form-control field-number">
                                </div>
                            </div>
                        </div>
<!--                        <script>-->
<!--                            $('#secret_salary')-->
<!--                                .bootstrapNumber({-->
<!--                                    upClass: 'success',-->
<!--                                    downClass: 'primary',-->
<!--                                    center: true-->
<!--                                });-->
<!--                        </script>-->
                        <div class="form-group">
                            <label for="overtime_salary" class="col-sm-2 control-label">加班工资</label>
                            <div class="col-sm-10 col-md-4">
                                <div class="input-group">
                                    <input id="overtime_salary" name="overtime_salary"
                                           value="{$data.overtime_salary|default=''}" placeholder="请输入加班工资"
                                           type="number" class="form-control field-number">
                                </div>
                            </div>
                        </div>
<!--                        <script>-->
<!--                            $('#overtime_salary')-->
<!--                                .bootstrapNumber({-->
<!--                                    upClass: 'success',-->
<!--                                    downClass: 'primary',-->
<!--                                    center: true-->
<!--                                });-->
<!--                        </script>-->
                        <div class="form-group">
                            <label for="fulltime_salary" class="col-sm-2 control-label">全勤奖</label>
                            <div class="col-sm-10 col-md-4">
                                <div class="input-group">
                                    <input id="fulltime_salary" name="fulltime_salary"
                                           value="{$data.fulltime_salary|default=''}" placeholder="请输入全勤奖" type="number"
                                           class="form-control field-number">
                                </div>
                            </div>
                        </div>
<!--                        <script>-->
<!--                            $('#fulltime_salary')-->
<!--                                .bootstrapNumber({-->
<!--                                    upClass: 'success',-->
<!--                                    downClass: 'primary',-->
<!--                                    center: true-->
<!--                                });-->
<!--                        </script>-->
                        <div class="form-group">
                            <label for="phone_salary" class="col-sm-2 control-label">通讯补助</label>
                            <div class="col-sm-10 col-md-4">
                                <div class="input-group">
                                    <input id="phone_salary" name="phone_salary" value="{$data.phone_salary|default=''}"
                                           placeholder="请输入通讯补助" type="number" class="form-control field-number">
                                </div>
                            </div>
                        </div>
<!--                        <script>-->
<!--                            $('#phone_salary')-->
<!--                                .bootstrapNumber({-->
<!--                                    upClass: 'success',-->
<!--                                    downClass: 'primary',-->
<!--                                    center: true-->
<!--                                });-->
<!--                        </script>-->
                        <div class="form-group">
                            <label for="housing_salary" class="col-sm-2 control-label">住房补贴</label>
                            <div class="col-sm-10 col-md-4">
                                <div class="input-group">
                                    <input id="housing_salary" name="housing_salary"
                                           value="{$data.housing_salary|default=''}" placeholder="请输入住房补贴" type="number"
                                           class="form-control field-number">
                                </div>
                            </div>
                        </div>
<!--                        <script>-->
<!--                            $('#housing_salary')-->
<!--                                .bootstrapNumber({-->
<!--                                    upClass: 'success',-->
<!--                                    downClass: 'primary',-->
<!--                                    center: true-->
<!--                                });-->
<!--                        </script>-->
                        <div class="form-group">
                            <label for="other_salary" class="col-sm-2 control-label">其他补贴</label>
                            <div class="col-sm-10 col-md-4">
                                <div class="input-group">
                                    <input id="other_salary" name="other_salary" value="{$data.other_salary|default=''}"
                                           placeholder="请输入其他补贴" type="number" class="form-control field-number">
                                </div>
                            </div>
                        </div>
<!--                        <script>-->
<!--                            $('#other_salary')-->
<!--                                .bootstrapNumber({-->
<!--                                    upClass: 'success',-->
<!--                                    downClass: 'primary',-->
<!--                                    center: true-->
<!--                                });-->
<!--                        </script>-->
                        <div class="form-group">
                            <label for="base_merit_salary" class="col-sm-2 control-label">绩效工资基数</label>
                            <div class="col-sm-10 col-md-4">
                                <div class="input-group">
                                    <input id="base_merit_salary" name="base_merit_salary"
                                           value="{$data.base_merit_salary|default=''}" placeholder="请输入绩效工资基数"
                                           type="number" class="form-control field-number">
                                </div>
                            </div>
                        </div>
<!--                        <script>-->
<!--                            $('#base_merit_salary')-->
<!--                                .bootstrapNumber({-->
<!--                                    upClass: 'success',-->
<!--                                    downClass: 'primary',-->
<!--                                    center: true-->
<!--                                });-->
<!--                        </script>-->
                        <div class="form-group">
                            <label for="social_security_salary" class="col-sm-2 control-label">社保工资</label>
                            <div class="col-sm-10 col-md-4">
                                <div class="input-group">
                                    <input id="social_security_salary" name="social_security_salary"
                                           value="{$data.social_security_salary|default=''}" placeholder="请输入社保工资"
                                           type="number" class="form-control field-number">
                                </div>
                            </div>
                        </div>
                        <!--                        <script>-->
                        <!--                            $('#social_security_salary')-->
                        <!--                                .bootstrapNumber({-->
                        <!--                                    upClass: 'success',-->
                        <!--                                    downClass: 'primary',-->
                        <!--                                    center: true-->
                        <!--                                });-->
                        <!--                        </script>-->
                        <div class="form-group">
                            <label for="deduct_social_money" class="col-sm-2 control-label">扣除社保</label>
                            <div class="col-sm-10 col-md-4">
                                <div class="input-group">
                                    <input id="deduct_social_money" name="deduct_social_money"
                                           value="{$data.deduct_social_money|default=''}" placeholder="请输入扣除社保"
                                           type="number" class="form-control field-number">
                                </div>
                            </div>
                        </div>
                        <!--                        <script>-->
                        <!--                            $('#deduct_social_money')-->
                        <!--                                .bootstrapNumber({-->
                        <!--                                    upClass: 'success',-->
                        <!--                                    downClass: 'primary',-->
                        <!--                                    center: true-->
                        <!--                                });-->
                        <!--                        </script>-->

                        <div class="form-group">
                            <label for="test_scale" class="col-sm-2 control-label">实习工资比例</label>
                            <div class="col-sm-10 col-md-4">
                                <input id="test_scale" name="test_scale" value="{$data.test_scale|default='0.8'}" placeholder="请输入实习工资比例" type="text" class="form-control field-text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="remarks" class="col-sm-2 control-label">备注</label>
                            <div class="col-sm-10 col-md-4">
                                <input id="remarks" name="remarks" value="{$data.remarks|default=''}" placeholder="请输入备注" type="text" class="form-control field-text">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="file" class="col-sm-2 control-label">附件</label>
                            <div class="col-sm-10 col-md-4">
                                <input id="file" name="file[]" placeholder="请上传附件" multiple="multiple" type="file"
                                       class="form-control field-multi-image">
                            </div>
                        </div>
                        <script>
                            $(function () {
                                $('#file').fileinput({
                                    "initialPreview": false,
                                    overwriteInitial: true,
                                    language: 'zh',
                                    browseLabel: '浏览',
                                    initialPreviewAsData: true,
                                    initialPreviewShowDelete: false,
                                    dropZoneEnabled: false,
                                    showUpload: false,
                                    showRemove: false,
                                    allowedFileTypes: ['image'],
                                    //默认限制10M
                                    maxFileSize: 10240,
                                {if isset($data) && $data->getData('file')}
                                initialPreview:{$data->getData('file')|raw},
                                {/if}
                                });
                            })
                        </script>
                        <div class="form-group">
                            <label for="status" class="col-sm-2 control-label">是否启用</label>
                            <div class="col-sm-10 col-md-4">
                                <input class="input-switch" id="status" value="1" {if(!isset($data)
                                       ||$data.status==1)}checked{/if} type="checkbox"/>
                                <input class="switch field-switch" placeholder="是否启用" name="status"
                                       value="{$data.status|default='1'}" hidden/>
                            </div>
                        </div>

                        <script>
                            $('#status').bootstrapSwitch({
                                onText: "是",
                                offText: "否",
                                onColor: "success",
                                offColor: "danger",
                                onSwitchChange: function (event, state) {
                                    $(event.target).closest('.bootstrap-switch').next().val(state ? '1' : '0').change();
                                }
                            });
                        </script>
                    </div>
                    <!-- 表单底部 -->
                    <div class="box-footer">
                        {:token()}
                        <div class="col-sm-2">
                        </div>
                        <div class="col-sm-10 col-md-4">
                            {if !isset($data)}
                            <div class="btn-group pull-right">
                                <label class="createContinue">
                                    <input type="checkbox" value="1" id="_create" name="_create"
                                           title="继续添加数据">继续添加</label>
                            </div>
                            {/if}
                            <div class="btn-group">
                                <button type="submit" class="btn flat btn-info dataFormSubmit">
                                    保存
                                </button>
                            </div>
                            <div class="btn-group">
                                <button type="reset" class="btn flat btn-default dataFormReset">
                                    重置
                                </button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>
<script>
    /** 表单验证 **/
    var url = window.location.href;
    var flag = true;
    if (url.indexOf('edit')>=0){
        flag = false;
    }
    //检验是否重复
    jQuery.validator.addMethod("checkname", function (value, element) {
        var resultval = false;
        jQuery.ajax({
            type: 'post',
            async:false,
            data:{'staff_id':value},
            url: "{:url('basic_salary/nameUnique')}",
            dataType: 'json',
            success: function (result) {
                if (result.code == 0) {
                    resultval = false;
                }
                else {
                    resultval = true;
                }
            },
            error: function () {
            }
        });
        return resultval;

    }, "您的名称重复，请重新输入");

    $('#dataForm').validate({

        rules: {
            'staff_id': {
                required: true,
                checkname:flag,
            },
            'status': {
                required: true,
            },

        },
        messages: {
            'staff_id': {
                required: "员工不能为空",
                checkname: '此员工信息已存在',
            },
            'status': {
                required: "是否启用不能为空",
            },

        },

    });

</script>
{/block}